/**
 * Created with Intellij IDEA
 * Description
 * User:ASUS
 * Date:2024-07-29
 * Time:16:42
 */
import java.util.Arrays;
public class Demo {
    public static void main(String[] args) {
        int[] arr={1,2,3,4};
        reverse(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void reverse(int[] arr){
        int left=0;
        int right=arr.length-1;
        while(left<right){
            int tmp=arr[left];
            arr[left]=arr[right];
            arr[right]=tmp;
            left++;
            right--;
        }
    }
    public static void main8(String[] args) {
        int[] arr={3,5,2,7};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void bubbleSort(int[] arr){
        for(int i=0;i<arr.length;i++){
            for(int j=1;j<arr.length-1;j++){
                if(arr[j-1]>arr[j]){
                    int tmp=arr[j-1];
                    arr[j-1]=arr[j];
                    arr[j]=tmp;
                }
            }
        }
    }
    public static void main7(String[] args) {
        int[] arr={1,2,3,4,5,6};
        System.out.println(binarySearch(arr,6));
    }
    public static int binarySearch(int[] arr,int toFind){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int mid=(left+right)/2;
            if(toFind<arr[mid]){
                //去左侧区间找
                right=mid-1;
            }else if(toFind>arr[mid]){
                //去右侧区间找
                left=mid+1;
            }else{
                //相等，说明找到了
                return mid;
            }
        }
        //循环结束，说明没找到
        return -1;
    }
    public static void main6(String[] args) {
        int[] arr={1,2,3,10,5,6};
        System.out.println(find(arr,10));
    }
    public static int find(int[] arr,int data){
        for(int i=0;i<arr.length;i++){
            if(arr[i]==data){
                return i;
            }
        }
        return -1;//表示没有找到
    }
    public static double avg(int[] arr){
        int sum=0;
        for(int x:arr){
            sum+=x;
        }
        return (double)sum/(double)arr.length;
    }
    public static void main5(String[] args) {
        int[] arr={1,2,3,4,5};
        String newArr=Arrays.toString(arr);
        System.out.println(newArr);
    }
    public static void main4(String[] args) {
        int[][] array={{1,2,3},{4,5,6}};
        int[][] array2=new int[][]{{1,2,3},{4,5,6}};
        int[][] array3=new int[2][3];
    }
        public static int[] fib(int n){
            if(n<=0){
                return null;
            }
            int[] array=new int[n];
            array[0]=array[1]=1;
            for(int i=2;i<n;++i){
                array[i]=array[i-1]+array[i-2];
            }
            return array;
        }
    public static void main3(String[] args) {
        int[] array=fib(10);
        for(int i=0;i<array.length;i++){
            System.out.println(array[i]);
        }
    }
    public static void main2(String[] args) {
        int[] arr={1,2,3};
        func(arr);
        System.out.println("arr[0]"+arr[0]);
    }
    public static void func(int[] a){
        a[0]=10;
        System.out.println("a[0]="+a[0]);
    }
    public static void main1(String[] args) {
        int num=0;
        func1(num);
        System.out.println("num="+num);
    }
    public static void func1(int x){
        x=10;
        System.out.println("x="+x);
    }
}
